package Treeset03;

import com.sun.source.tree.Tree;

import java.util.Comparator;
import java.util.TreeSet;

public class Demo {
    public static void main(String[] args) {
        TreeSet<String> set = new TreeSet<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int length1 = o1.length();
                int length2 = o2.length();
                if (length1 != length2) {
                    return length1 - length2;
                }else{
                    return o1.compareTo(o2);
                }
            }
        });

        set.add("你好");
        set.add("世界");
        set.add("我爱编程");
        set.add("Java");
        set.add("Python");
        set.add("C++");
        set.add("JavaScript");

        for (String str : set) {
            System.out.println(str);
        }
    }
}
